package com.slimerevenge.model;

import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.slimerevenge.view.WorldRenderer;

public class Block {
	public static final float SIZE = 1f;
	private Body block;
	
	public Body getBody()
	{
		return block;
	}
	
	public Vector2 getPosition() {
		return this.getBody().getPosition();
	}

	public Rectangle getBounds() {
		return bounds;
	}

	Vector2 position = new Vector2();
	Rectangle bounds = new Rectangle();

	public Block(Vector2 pos,World world) {
		this.position = pos;
		this.bounds.width = SIZE;
		this.bounds.height = SIZE;
		
		//This part onwards is related to box2d's player initialization
		BodyDef blockBodyDef = new BodyDef();
		//We set our body to dynamic, for something like ground which doesn't move we would set it to StaticBody
		blockBodyDef.type = BodyDef.BodyType.StaticBody;
		blockBodyDef.position.set(this.position.x, this.position.y);
		block = world.createBody(blockBodyDef);
		
		PolygonShape blockShape = new PolygonShape();
		//blockShape.setAsBox(this.bounds.width / (2 * WorldRenderer.PIXELS_PER_METER),
		//		this.bounds.height / (2 * WorldRenderer.PIXELS_PER_METER));
		blockShape.setAsBox(this.bounds.width,
				this.bounds.height);
		block.setFixedRotation(true);
		
		//Create a fixture and attach it to player
		FixtureDef blockFixtureDef = new FixtureDef();

		blockFixtureDef.shape = blockShape;
		blockFixtureDef.density = 1.0f;
		blockFixtureDef.friction = 0.05f;
		
		block.createFixture(blockFixtureDef);
		//block.getFixtureList().get(0).setUserData("block");
		blockShape.dispose();
	}
}
